{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Title: #速算机器人"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Difficulty: #Easy"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Category Title: #Algorithms"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Tag Slug: #math #string #simulation"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Name Translated: #数学 #字符串 #模拟"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solution Name: calculate"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Title: #速算机器人"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Content:\n",
    "小扣在秋日市集发现了一款速算机器人。店家对机器人说出两个数字（记作 `x` 和 `y`），请小扣说出计算指令：\r\n",
    "- `\"A\"` 运算：使 `x = 2 * x + y`；\r\n",
    "- `\"B\"` 运算：使 `y = 2 * y + x`。\r\n",
    "\r\n",
    "在本次游戏中，店家说出的数字为 `x = 1` 和 `y = 0`，小扣说出的计算指令记作仅由大写字母 `A`、`B` 组成的字符串 `s`，字符串中字符的顺序表示计算顺序，请返回最终 `x` 与 `y` 的和为多少。\r\n",
    "\r\n",
    "**示例 1：**\r\n",
    ">输入：`s = \"AB\"`\r\n",
    "> \r\n",
    ">输出：`4`\r\n",
    "> \r\n",
    ">解释：\r\n",
    ">经过一次 A 运算后，x = 2, y = 0。\r\n",
    ">再经过一次 B 运算，x = 2, y = 2。\r\n",
    ">最终 x 与 y 之和为 4。\r\n",
    "\r\n",
    "**提示：**\r\n",
    "- `0 <= s.length <= 10`\r\n",
    "- `s` 由 `'A'` 和 `'B'` 组成\r\n",
    "\r\n",
    "\r\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Description: [nGK0Fy](https://leetcode.cn/problems/nGK0Fy/description/)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solutions: [nGK0Fy](https://leetcode.cn/problems/nGK0Fy/solutions/)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "test_cases = ['\"AB\"']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def calculate(self, s: str) -> int:\n",
    "        x =1\n",
    "        y =0\n",
    "        for i in s:\n",
    "            if i =='A':\n",
    "                x = 2*x+y\n",
    "            if i == 'B':\n",
    "                y = 2*y+x\n",
    "        return x+y"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def calculate(self, s: str) -> int:\n",
    "        x, y = 1, 0\n",
    "        for i in s:\n",
    "            if i == \"A\":\n",
    "                x = 2 * x + y\n",
    "            else:\n",
    "                y = 2 * y + x\n",
    "        return x + y"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def calculate(self, s: str) -> int:\n",
    "        return 2**len(s)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def calculate(self, s: str) -> int:\n",
    "        x, y = 1, 0\n",
    "        s = list(map(str, ''.join(s)))\n",
    "        for i in range(len(s)):\n",
    "            if s[i] == \"A\":\n",
    "                x = 2 * x + y\n",
    "            else:\n",
    "                y = 2 * y + x\n",
    "        return x + y"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def calculate(self, s: str) -> int:\n",
    "        x = 1\n",
    "        y = 0\n",
    "        #\"A\" 运算：使 x = 2 * x + y；\n",
    "        #\"B\" 运算：使 y = 2 * y + x。\n",
    "        for i in s:\n",
    "            if i == \"A\":\n",
    "                x = 2 * x + y\n",
    "            else:\n",
    "                y = 2 * y + x\n",
    "        return x+y"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def calculate(self, s: str) -> int:\n",
    "        return 2 ** len(s)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def calculate(self, s: str) -> int:\n",
    "        return 2 ** len(s)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def calculate(self, s: str) -> int:\n",
    "        return 1 << len(s)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def calculate(self, s: str) -> int:\n",
    "        x=1\n",
    "        y=0\n",
    "        for i in range(len(s)):\n",
    "            if s[i]=='A':\n",
    "                x=2*x+y\n",
    "            elif s[i]=='B':\n",
    "                y=2*y+x\n",
    "        return x+y"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def calculate(self, s: str) -> int:\n",
    "        # return 2**len(s)\n",
    "        return 1 << len(s)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def calculate(self, s: str) -> int:\n",
    "        x = 1\n",
    "        y = 0\n",
    "        # if not s:\n",
    "        #     return x\n",
    "        # else:\n",
    "        for i in s:\n",
    "            if i == 'A':\n",
    "                x = 2*x+y\n",
    "            else:\n",
    "                y = 2*y+x\n",
    "        return x+y"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def calculate(self, s: str) -> int:\n",
    "        x = 1\n",
    "        y = 0\n",
    "\n",
    "        for ss in s:\n",
    "            if ss == 'A':\n",
    "                x = 2 * x + y\n",
    "            else:\n",
    "                y = 2 * y + x\n",
    "        return x + y"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def calculate(self, s: str) -> int:\n",
    "        x,y = 1,0\n",
    "        for w in s:\n",
    "            if w == 'A':\n",
    "                x = 2 * x + y\n",
    "            if w == 'B':\n",
    "                y = 2 * y + x\n",
    "        return x + y"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def calculate(self, s: str) -> int:\n",
    "        A=lambda x,y: (2*x+y,y)\n",
    "        B = lambda x,y: (x,2*y+x)\n",
    "\n",
    "        x,y =1,0\n",
    "        for f in s:\n",
    "            if f == 'A':\n",
    "                x,y = A(x,y)\n",
    "            elif f == 'B':\n",
    "                x,y = B(x,y)\n",
    "            else:\n",
    "                exit('指令仅由大写字母A或B组成')\n",
    "        return x+y\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def calculate(self, s: str) -> int:\n",
    "        x, y = 1, 0\n",
    "        for c in s:\n",
    "            if c=='A':\n",
    "                x = 2*x+y\n",
    "            else:\n",
    "                y = 2*y+x\n",
    "        return x+y"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def calculate(self, s: str) -> int:\n",
    "        x=1\n",
    "        y=0\n",
    "        l=len(s)\n",
    "        for i in s:\n",
    "            if(i=='A'): x=2*x+y\n",
    "            else: y=2*y+x\n",
    "            print(i)\n",
    "        return x+y "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def calculate(self, s: str) -> int:\n",
    "        x = 1\n",
    "        y = 0\n",
    "        for i in s:\n",
    "            if i == \"A\":\n",
    "                x = 2*x+y\n",
    "            elif i == \"B\":\n",
    "                y = 2*y+x\n",
    "        return x+y"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def calculate(self, s: str) -> int:\n",
    "        x,y=1,0\n",
    "        for i in s:\n",
    "            if i=='A':x=2*x+y\n",
    "            else:y=2*y+x\n",
    "        return x+y"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def calculate(self, s: str) -> int:\n",
    "     return 2 ** len(s)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def calculate(self, s: str) -> int:\n",
    "        x, y = 1, 0\n",
    "        for c in s:\n",
    "            if c=='A':\n",
    "                x = 2*x+y\n",
    "            else:\n",
    "                y = 2*y+x\n",
    "        return x+y"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def calculate(self, s: str) -> int:\n",
    "        x = 1\n",
    "        y = 0\n",
    "        for c in s:\n",
    "            if c == \"A\":\n",
    "                x = A(x, y)\n",
    "            else:\n",
    "                y = B(x, y)\n",
    "        return x + y\n",
    "\n",
    "\n",
    "def A(x: int, y: int) -> int:\n",
    "    return 2 * x + y\n",
    "\n",
    "\n",
    "def B(x: int, y: int) -> int:\n",
    "    return 2 * y + x"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def calculate(self, s: str) -> int:\n",
    "        return 1 << len(s)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def calculate(self, s: str) -> int:\n",
    "        x = 1\n",
    "        y = 0\n",
    "        \n",
    "        for i in s:\n",
    "            if i == 'A':\n",
    "                x = 2*x + y\n",
    "            if i == 'B':\n",
    "                y = 2*y + x\n",
    "        return x+y"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def calculate(self, s: str) -> int:\n",
    "        x, y = 1, 0\n",
    "        for i in s:\n",
    "            if i == 'A':\n",
    "                x = (x << 1) + y\n",
    "            else:\n",
    "                y = (y << 1) + x\n",
    "        return x + y\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def calculate(self, s: str) -> int:\n",
    "        return 2 ** len(s)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def calculate(self, s: str) -> int:\n",
    "        x = 1\n",
    "        y = 0\n",
    "        for i in s:\n",
    "            if i=='A':\n",
    "                x = 2*x+y\n",
    "            else:\n",
    "                y = 2*y+x\n",
    "        return x + y\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def calculate(self, s: str) -> int:\n",
    "        return 2 ** len(s)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def calculate(self, s: str) -> int:\n",
    "        \n",
    "        x = 1\n",
    "        y = 0\n",
    "        for order in s:\n",
    "            if order == 'A':\n",
    "                x = 2 * x + y\n",
    "            else:\n",
    "                y = 2 * y + x\n",
    "        \n",
    "        return x + y\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def calculate(self, s: str) -> int:\n",
    "        x,y=1,0\n",
    "        for i in s:\n",
    "            if i=='A':\n",
    "                x=2*x+y\n",
    "            else:\n",
    "                y=2*y+x\n",
    "        return x+y"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def calculate(self, s: str) -> int:\n",
    "        ans = 0 \n",
    "        x=1\n",
    "        y=0\n",
    "        for i in s:\n",
    "            if i == \"A\":\n",
    "                x = 2 * x + y\n",
    "            else:\n",
    "                y = 2 * y + x\n",
    "        return x+y\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def calculate(self, s: str) -> int:\n",
    "        x=1\n",
    "        y=0\n",
    "        for i in s:\n",
    "            if i=='A':\n",
    "               x = 2 * x + y\n",
    "            else:\n",
    "                y = 2 * y + x\n",
    "        return x+y"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def calculate(self, s: str) -> int:\n",
    "        x, y = 1, 0\n",
    "        for i in s:\n",
    "            if i == 'A':\n",
    "                x = x*2 + y\n",
    "            else:\n",
    "                y = y*2 + x\n",
    "        return x+y"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def calculate(self, s: str) -> int:\n",
    "        A=lambda x,y: (2*x+y,y)\n",
    "        B = lambda x,y: (x,2*y+x)\n",
    "\n",
    "        x,y =1,0\n",
    "        for f in s:\n",
    "            if f == 'A':\n",
    "                x,y = A(x,y)\n",
    "            elif f == 'B':\n",
    "                x,y = B(x,y)\n",
    "            else:\n",
    "                exit('指令仅有大写字母A或B组成')\n",
    "        return x+y\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def calculate(self, s: str) -> int:\n",
    "        x, y = 1, 0\n",
    "        for c in s:\n",
    "            if c == 'A':\n",
    "                x = 2*x + y\n",
    "            else:\n",
    "                y = 2*y+x\n",
    "        return x+y"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def calculate(self, s: str) -> int:\n",
    "        x,y=1,0\n",
    "        for i in range(len(s)):\n",
    "            if s[i] == 'A':\n",
    "                x = 2 * x + y\n",
    "            elif s[i] == 'B':\n",
    "                y = 2 * y + x\n",
    "        \n",
    "        return x+y\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def calculate(self, s: str) -> int:\n",
    "        return 2**len(s)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def calculate(self, s: str) -> int:\n",
    "        le = len(s)\n",
    "        return 1 << le"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def calculate(self, s: str) -> int:\n",
    "        return 2**len(s)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def calculate(self, s: str) -> int:\n",
    "        x = 1\n",
    "        y = 0\n",
    "\n",
    "        for i in s:\n",
    "            if i == 'A':\n",
    "                x = x * 2 + y\n",
    "            if i == 'B':\n",
    "                y = y * 2 + x\n",
    "        return x + y\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def calculate(self, s: str) -> int:\n",
    "        x = 0\n",
    "        y = 1\n",
    "        for i in s:\n",
    "            if i == \"A\":\n",
    "                x = 2 * x + y\n",
    "            else:\n",
    "                y = 2 * y + x\n",
    "        return x+y"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def calculate(self, s: str) -> int:\n",
    "        return 2 ** len(s)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def calculate(self, s: str) -> int:\n",
    "        x, y = 0, 1\n",
    "        for item in s:\n",
    "            if item == 'A':\n",
    "                x = 2*x+y\n",
    "            elif  item == 'B':\n",
    "                y = 2*y+x\n",
    "        return x+y\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def calculate(self, s: str) -> int:\n",
    "        x = 1\n",
    "        y = 0\n",
    "        for sss in s:\n",
    "            if sss == 'A':\n",
    "                x = 2 * x + y\n",
    "            if sss == 'B':\n",
    "                y = 2 * y + x\n",
    "        return x + y"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def calculate(self, s: str) -> int:\n",
    "        x, y = 1, 0\n",
    "        for i in s:\n",
    "            if i == 'A':\n",
    "                x = (x << 1) + y\n",
    "            else:\n",
    "                y = (y << 1) + x\n",
    "        return x + y\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def calculate(self, s: str) -> int:\n",
    "        x = 1\n",
    "        y = 0\n",
    "        for i in s:\n",
    "            if i == \"A\":\n",
    "               x = 2 * x + y\n",
    "            elif i == \"B\":\n",
    "                y = 2 * y + x\n",
    "        return x + y\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def calculate(self, s: str) -> int:\n",
    "        x,y=1,0\n",
    "        for i in s:\n",
    "            if i==\"A\":\n",
    "                x=2*x+y\n",
    "            else:\n",
    "                y=2*y+x\n",
    "        return x+y"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def calculate(self, s: str) -> int:\n",
    "        x = 1\n",
    "        y = 0\n",
    "        for i in range(0,len(s)):\n",
    "            if s[i] == 'A':\n",
    "                x = 2*x+y\n",
    "            else:\n",
    "                y = 2*y+x\n",
    "        return x+y"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def calculate(self, s: str) -> int:\n",
    "        a, b = 1, 0\n",
    "        for cs in s:\n",
    "            if cs == \"A\":\n",
    "                a = a * 2 + b\n",
    "            else:\n",
    "                b = b * 2 + a\n",
    "        return a + b\n",
    "\n",
    "\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def calculate(self, s: str) -> int:\n",
    "\n",
    "        length = len(s)    # 表示进行几次计算 \n",
    "        x = 1\n",
    "        y = 0\n",
    "        for i in range(length):\n",
    "            if s[i] == \"A\":\n",
    "                x = 2 * x + y\n",
    "                \n",
    "            if s[i] == \"B\":\n",
    "                y = 2 * y + x\n",
    "        return x + y\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def calculate(self, s: str) -> int:\n",
    "        x = 1\n",
    "        y = 0\n",
    "        for i in s:\n",
    "            if i=='A':\n",
    "                x = 2*x + y\n",
    "            else:\n",
    "                y = 2*y+x\n",
    "        return x+y"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def calculate(self, s: str) -> int:\n",
    "        return 2 ** len(s)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def calculate(self, s: str) -> int:\n",
    "        return max(2 ** len(s), 1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def calculate(self, s: str) -> int:\n",
    "        x = 1\n",
    "        y = 0\n",
    "        for c in s:\n",
    "            if c == \"A\":\n",
    "                x = 2 * x + y\n",
    "            else:\n",
    "                y = 2 * y + x\n",
    "        return x+y"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def calculate(self, s: str) -> int:\n",
    "        x = 1\n",
    "        y = 0\n",
    "        for ch in s:\n",
    "            if ch == \"A\":\n",
    "                x = 2 * x + y\n",
    "            else:\n",
    "                y = 2 * y + x\n",
    "        return x + y"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def calculate(self, s: str) -> int:\n",
    "        return 1 << len(s)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def calculate(self, s: str) -> int:\n",
    "        x,y=1,0\n",
    "        for i in s:\n",
    "            if i==\"A\":\n",
    "                x=2*x+y\n",
    "            else:\n",
    "                y=2*y+x\n",
    "        return x+y\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def calculate(self, s: str) -> int:\n",
    "        x, y = 1, 0 \n",
    "        for i in s:\n",
    "            if i == \"A\": \n",
    "                x = 2 * x + y\n",
    "            elif i == \"B\":\n",
    "                y = 2 * y + x\n",
    "        return x + y"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def calculate(self, s: str) -> int:\n",
    "        ans = 0 \n",
    "        x=1\n",
    "        y=0\n",
    "        for i in s:\n",
    "            if i == \"A\":\n",
    "                x = 2 * x + y\n",
    "            else:\n",
    "                y = 2 * y + x\n",
    "        return x+y\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def calculate(self, s: str) -> int:\n",
    "\n",
    "\n",
    "\n",
    "        x, y = 1, 0\n",
    "\n",
    "\n",
    "        for c in s:\n",
    "\n",
    "            if c == \"A\":\n",
    "                x, y =  2 * x + y, y\n",
    "\n",
    "            else:\n",
    "                x, y = x, 2 * y + x\n",
    "\n",
    "        return x + y"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def calculate(self, s: str) -> int:\n",
    "        x = 1\n",
    "        y = 0\n",
    "        for instruction in list(s):\n",
    "            if instruction == 'A':\n",
    "                x = 2 * x + y\n",
    "            elif instruction == 'B':\n",
    "                y = 2 * y + x\n",
    "        return x + y"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def calculate(self, s: str) -> int:\n",
    "        return 2**len(s)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def calculate(self, s: str) -> int:\n",
    "        x,y=1,0\n",
    "        for v in s:\n",
    "            if v =='A':\n",
    "                x = 2*x+y\n",
    "            else:\n",
    "                y=2*y+x\n",
    "        return x+y"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def calculate(self, s: str) -> int:\n",
    "        x,y = 1,0\n",
    "        for i in s:\n",
    "            if s == \"A\" :\n",
    "                x = 2*x+y\n",
    "            else:\n",
    "                y = 2*y+x\n",
    "\n",
    "        return x+y"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def calculate(self, s: str) -> int:\n",
    "        x=1\n",
    "        y=0\n",
    "        for i in s:\n",
    "            if i=='A':\n",
    "                x=2*x+y\n",
    "            else:\n",
    "                y=2*y+x\n",
    "        return x+y\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def calculate(self, s: str) -> int:\n",
    "        x=1\n",
    "        y=0\n",
    "        for i in s:\n",
    "            if i=='A':x = 2 * x + y\n",
    "            else:y = 2 * y + x\n",
    "        return x+y"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def calculate(self, s: str) -> int:\n",
    "        x = 1 \n",
    "        y = 0\n",
    "        for ss in s:\n",
    "            if ss == 'A':\n",
    "                x = 2*x + y \n",
    "            elif ss == 'B':\n",
    "                y = 2*y + x\n",
    "        \n",
    "        return x+y"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def calculate(self, s: str) -> int:\n",
    "        x,y=1,0\n",
    "        for i in s:\n",
    "            if i=='A':\n",
    "                x=2*x+y\n",
    "            elif i=='B':\n",
    "                y=2*y+x\n",
    "        return x+y"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def calculate(self, s: str) -> int:\n",
    "        x, y = 1, 0\n",
    "        for _ in s:\n",
    "            if _ == 'A':\n",
    "                x = 2*x + y\n",
    "            else:\n",
    "                y = 2*y + x\n",
    "        return x + y"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def calculate(self, s: str) -> int:\n",
    "        x = 1\n",
    "        y = 0\n",
    "        for i in s:\n",
    "            if i == \"A\":\n",
    "                x = 2 * x + y\n",
    "            else:\n",
    "                y = 2 * y + x\n",
    "        return x + y"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def calculate(self, s: str) -> int:\n",
    "        return 1 << len(s)"
   ]
  }
 ],
 "metadata": {},
 "nbformat": 4,
 "nbformat_minor": 2
}
